package com.ruoyi.web.controller.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.service.ISysConfigService;

/**
 * 乡村介绍信息接口
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/api/village")
public class VillageIntroController extends BaseController
{
    @Autowired
    private ISysConfigService configService;

    /**
     * 获取乡村介绍信息
     */
    @GetMapping("/intro")
    public AjaxResult getVillageIntro()
    {
        try
        {
            // 从参数配置中获取乡村介绍JSON数据
            String introJson = configService.selectConfigByKey("village.intro");
            
            if (introJson == null || introJson.isEmpty())
            {
                return error("乡村介绍信息未配置");
            }
            
            // 解析JSON字符串为对象
            com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();
            Object introData = mapper.readValue(introJson, Object.class);
            
            return success(introData);
        }
        catch (Exception e)
        {
            logger.error("获取乡村介绍信息失败", e);
            return error("获取乡村介绍信息失败：" + e.getMessage());
        }
    }
}
